package com.card.game.room;

import java.util.Arrays;
import java.util.List;

import com.google.common.collect.Lists;

/**   
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author siyunlong  
 * @date 2016年8月31日 下午4:52:21 
 * @version V1.0   
 */
public class BetRegion {
	private int[] btv = new int[3];
	private transient int total;
	private transient int num;
	private List<Integer> rb0 =	 Lists.newArrayList();
	private List<Integer> rb1 =	 Lists.newArrayList();
	private List<Integer> rb2 =	 Lists.newArrayList();
	
	public BetRegion() {
		clear();
	}

	public void addBet(int index,int v) {
		index = index - 1;
		if(index < 0 || index > 2) {
			index = 0;
		}
		btv[index] = btv[index]+v;
		addRegionBet(index, v);
		this.total += v;
		this.num++;
	}
	
	public void addRegionBet(int index,int v) {
		List<Integer> vv = null;
		if(index == 0) vv = rb0;
		if(index == 1) vv = rb1;
		if(index == 2) vv = rb2;
		if(null == vv) vv = rb0;
		vv.add(v);
	}
	
	public int getTotal() {
		return total;
	}
	
	public int getBetValueByIndex(int index) {
		try {
			index = index - 1;
			return btv[index];
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	public int calScore(boolean[] results,boolean[] baozi) {
		int score = 0;
		for (int i = 0; i < btv.length; i++) {
			boolean isDouble = isDouble(results[i], baozi[0], baozi[i+1]);
			int fanbei = isDouble?2:1;
			if(results[i]) {
				score += btv[i]*fanbei;
			}else{
				score -= btv[i]*fanbei;
			}
		}
		return score;
	}
	
	public boolean isDouble(boolean isWin,boolean zhuangBaozi,boolean baozi) {
		if(zhuangBaozi && baozi) {
			return !isWin;
		}
		return zhuangBaozi||baozi;
	}
	
	public void clear() {
		for (int i = 0; i < btv.length; i++) {
			btv[i] = 0;
		}
		this.total = 0;
		this.num = 0;
		rb0.clear();
		rb1.clear();
		rb2.clear();
	}

	public static void main(String[] args) {
		int[] btv = new int[3];
		System.out.println(Arrays.toString(btv));
	}
}
